//
//  EmploymentViewController.m
//  work
//
//  Created by 徐宏飞 on 16/5/19.
//  Copyright © 2016年 方伟. All rights reserved.
//

#import "EmploymentViewController.h"
#import "XRCarouselView.h"
#import "CustomAlertView.h"



@interface EmploymentViewController ()<XRCarouselViewDelegate>

@property (nonatomic, strong) UIScrollView *baseScroll;
@property (nonatomic, strong) XRCarouselView *carouselView;  //轮播图
@property (nonatomic, strong) NSArray *imgArrays;


@property (nonatomic, strong) UILabel *lblTitle;
@property (nonatomic, strong) UILabel *lblPrice;
@property (nonatomic, strong) UILabel *lblAddress;
@property (nonatomic, strong) UILabel *lblWorkDate;
@property (nonatomic, strong) UILabel *lblArea;

@property (nonatomic, strong) UILabel *lblSpecial;
@property (nonatomic, strong) UILabel *lblSpecialContent;

@property (nonatomic, strong) UIButton *btnTakeJob;


@end

@implementation EmploymentViewController



#pragma mark - life cycle
- (void)initNavigationBar
{
    self.enableReturnButton = YES;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.title = @"详情";
    
    
    [self.view addSubview:self.baseScroll];

    //轮播图
    [self ConfigurationCarouselView];
    
    //信息
    [self ConfigurationEmploymentInfo];
    
    //赋值
    [self getData];
    
    
    [self.view addSubview:self.btnTakeJob];
    
}


- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    
    NSString *identifier = [[NSUserDefaults standardUserDefaults] objectForKey:@"identifier"];
    if ([self.identifier isEqualToString:identifier]) {
        self.btnTakeJob.enabled = NO;
    } else {
        self.btnTakeJob.enabled = YES;
    }
    
    [MobClick beginLogPageView:@"Home-details"];//("PageOne"为页面名称，可自定义)

}



- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    [MobClick endLogPageView:@"Home-details"];
}


#pragma mark - UITableViewDelegate




#pragma mark - CustomDelegate
- (void)carouselView:(XRCarouselView *)carouselView didClickImage:(NSInteger)index {
    NSLog(@"点击了第%ld张图片", index);
    
}





#pragma mark - event response
- (void)takeJobAction:(UIButton *)btn{
    NSLog(@"我要接活");
    
    [[NSUserDefaults standardUserDefaults] setObject:self.identifier forKey:@"identifier"];
    
    NSString *identifier = [[NSUserDefaults standardUserDefaults] objectForKey:@"identifier"];
    if ([self.identifier isEqualToString:identifier]) {
        CustomAlertView *alertV = [[CustomAlertView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
        [self.view addSubview:alertV];
        self.btnTakeJob.enabled = NO;
    }
    
    
}


#pragma mark - private methods
- (void)ConfigurationCarouselView{
    //创建轮播图
    
    /**
     *  通过代码创建
     */
    self.carouselView = [XRCarouselView carouselViewWithImageArray:self.imgArrays describeArray:nil];
    
    //设置frame
    self.carouselView.frame = CGRectMake(0, 0, SCREEN_WIDTH, 140);
    
    
    //用代理处理图片点击，如果两个都实现，block优先级高于代理
    self.carouselView.delegate = self;
    
    
    _carouselView.changeMode = ChangeModeFade;
    
    //设置每张图片的停留时间
    _carouselView.time = 4;
    
    //设置分页控件的位置，默认为PositionBottomCenter
    _carouselView.pagePosition = PositionBottomRight;
    
    [self.baseScroll addSubview:_carouselView];
    
    
}

- (void)ConfigurationEmploymentInfo{
    
    [self.baseScroll addSubview:self.lblTitle];
    [self.baseScroll addSubview:self.lblPrice];
    [self.baseScroll addSubview:self.lblAddress];
    [self.baseScroll addSubview:self.lblWorkDate];
    [self.baseScroll addSubview:self.lblArea];
    [self.baseScroll addSubview:self.lblSpecial];
    [self.baseScroll addSubview:self.lblSpecialContent];
    
}

- (void)getData{
    self.lblTitle.text = @"油漆工";
    self.lblPrice.text = @"[30元／平米-35元／平米]";
    self.lblAddress.text = @"杭州－西湖区－留下镇－un公社";
    self.lblWorkDate.text = @"施工时间：6月1日——7月1日";
    self.lblArea.text = @"面积：100平米";
    self.lblSpecialContent.text = @"问题描述: 为什么别人给我转账不收服务费,我转账却要服务费,别人也是拿电脑转账的[专业]答案:支付宝转账支付宝是免费的,但会根据对方的账号有限制额度;支付宝转账银行卡是收费的,标准如下:到账时间服务费率服务费下限服务费上限2小时到账0.20%2";
    
    CGSize size = [NSString sizeWithText:self.lblSpecialContent.text maxSize:CGSizeMake(SCREEN_WIDTH - 2*26*WID, MAXFLOAT) font:FW_XWID_FONT(14)];
    
    CGFloat x = 26*WID;
    CGFloat y = 230;
    CGFloat w = size.width;
    CGFloat h = size.height;
    
    self.lblSpecialContent.frame = CGRectMake(x, y + 89, w, h);
    
}



#pragma mark - gettsers and setters
- (UIScrollView *)baseScroll{
    if (!_baseScroll) {
        _baseScroll = [[UIScrollView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
        _baseScroll.contentSize = CGSizeMake(0, SCREEN_HEIGHT + 1);
    }
    return _baseScroll;
}

- (NSArray *)imgArrays{
    if (!_imgArrays) {
        NSMutableArray *array = [NSMutableArray array];
        UIImage *image0 = [UIImage imageNamed:@"hbg"];
        [array addObject:image0];
        
        UIImage *image1 = [UIImage imageNamed:@"288_6296"];
        [array addObject:image1];
        
        UIImage *image2 = [UIImage imageNamed:@"imq.jpg"];
        [array addObject:image2];
        
        
        UIImage *image3 = [UIImage imageNamed:@"imw.jpg"];
        [array addObject:image3];
        _imgArrays = array;
    }
    return _imgArrays;
}
//@property (nonatomic, strong) UILabel *lblTitle;
//@property (nonatomic, strong) UILabel *lblPrice;
//@property (nonatomic, strong) UILabel *lblAddress;
//@property (nonatomic, strong) UILabel *lblWorkDate;
//@property (nonatomic, strong) UILabel *lblArea;



- (UILabel *)lblTitle{
    if (!_lblTitle) {
        _lblTitle = [[UILabel alloc] initWithFrame:CGRectMake(26*WID, 150, 100*WID, 30*WID)];
        _lblTitle.font = FW_XWID_FONT(20);
        _lblTitle.textColor = UIColorFromRGB(0x696969);
    }
    return _lblTitle;
}

- (UILabel *)lblPrice{
    if (!_lblPrice) {
        _lblPrice = [[UILabel alloc] initWithFrame:CGRectMake(SCREEN_WIDTH -190*WID, 155, 190*WID, 20*WID)];
        _lblPrice.font = FW_XWID_FONT(14);
        _lblPrice.textColor = UIColorFromRGB(0x696969);
    }
    return _lblPrice;
}

- (UILabel *)lblAddress{
    if (!_lblAddress) {
        _lblAddress = [[UILabel alloc] initWithFrame:CGRectMake(26*WID, 190, 200*WID, 20*WID)];
        _lblAddress.font = FW_XWID_FONT(14);
        _lblAddress.textColor = UIColorFromRGB(0x696969);
    }
    return _lblAddress;
}

- (UILabel *)lblWorkDate{
    if (!_lblWorkDate) {
        _lblWorkDate = [[UILabel alloc] initWithFrame:CGRectMake(26*WID, 190 + 25, 200*WID, 20*WID)];
        _lblWorkDate.font = FW_XWID_FONT(14);
        _lblWorkDate.textColor = UIColorFromRGB(0x696969);
    }
    return _lblWorkDate;
}

- (UILabel *)lblArea{
    if (!_lblArea) {
        _lblArea = [[UILabel alloc] initWithFrame:CGRectMake(26*WID, 190 + 2*25, 200*WID, 20*WID)];
        _lblArea.font = FW_XWID_FONT(14);
        _lblArea.textColor = UIColorFromRGB(0x696969);
    }
    return _lblArea;
}

- (UILabel *)lblSpecial{
    if (!_lblSpecial) {
        _lblSpecial = [[UILabel alloc] initWithFrame:CGRectMake(26*WID, 190 + 4*25, 200*WID, 20*WID)];
        _lblSpecial.font = FW_XWID_FONT(14);
        _lblSpecial.textColor = UIColorFromRGB(0x696969);
        _lblSpecial.text = @"特殊要求:";
    }
    return _lblSpecial;
}

- (UILabel *)lblSpecialContent{
    if (!_lblSpecialContent) {
        
        _lblSpecialContent = [[UILabel alloc] init];
        _lblSpecialContent.font = FW_XWID_FONT(14);
        _lblSpecialContent.textColor = UIColorFromRGB(0x696969);
        _lblSpecialContent.numberOfLines = 0;
    }
    return _lblSpecialContent;
}

- (UIButton *)btnTakeJob{
    if (!_btnTakeJob) {
        _btnTakeJob = [UIButton buttonWithType:UIButtonTypeCustom];
        [_btnTakeJob setBackgroundImage:FW_IMAGE(@"矩形nor") forState:UIControlStateNormal];
        [_btnTakeJob setTitle:@"我要接活" forState:UIControlStateNormal];
        [_btnTakeJob setBackgroundImage:FW_IMAGE(@"矩形hl") forState:UIControlStateDisabled];
        [_btnTakeJob setTitle:@"已投简历，请耐心等待" forState:UIControlStateDisabled];

        
        _btnTakeJob.titleLabel.font = FW_FONT(12);
        CGFloat btnX = 30;
        CGFloat btnY = SCREEN_HEIGHT - 120;
        CGFloat btnW = SCREEN_WIDTH - 2*30;
        CGFloat btnH = 30;
        _btnTakeJob.frame = CGRectMake(btnX, btnY, btnW, btnH);
        [_btnTakeJob addTarget:self action:@selector(takeJobAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _btnTakeJob;
}






- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
